package hqu.jann.dao;

import hqu.jann.pojo.Course;

public class CourseList {
    public Course[] courses;

    //初始化
    public void initial(int count) {
        courses = new Course[count];
    }

    //添加课程
    public void add(Course course) {
        courses[course.no] = course;
    }

    public Course select(int no){
        return courses[no];
    }

    //删除课程
    public void delete(int no) {
        courses[no] = null;
    }

    public Course[] list() {
        int count = 0;
        for (int i = 0; i < courses.length; i++) {
            if (courses[i] != null) {
                count++;
            }
        }
        Course[] list = new Course[count];
        int j = 0;
        for (int i = 0; i < courses.length; i++) {
            if (courses[i] != null) {
                list[j] = courses[i];
                j++;
            }
        }

        return list;
    }
}
